﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BonsaiScrum.Core.Command;
using BonsaiScrum.Bus;
using BonsaiScrum.Core.Persistance;
using BonsaiScrum.Core.Domain;

namespace BonsaiScrum.Core.CommandHandlers
{
    public class CreateNewStoryHandler : ICommandHandler<CreateNewStory>
    {
        private IDomainRepository _domainRepository;

        public CreateNewStoryHandler(IDomainRepository domainRepository)
        {
            _domainRepository = domainRepository;
        }

        public void Handle(CreateNewStory message)
        {
            var user = _domainRepository.GetById<User>(message.ScrumMasterId);
            var project = _domainRepository.GetById<Project>(message.ProjectId);
            var scrumMaster = user.GetRole<ScrumMaster>();

            scrumMaster.CreateStoryForProject(project, message.Description);
        }
    }
}
